//
//  RDHomeTodayTableViewCell.m
//  ReverseDiabetes
//
//  Created by 王佩璇 on 2024/8/25.
//

#import "RDHomeTodayTableViewCell.h"
#import "RDHomeTodayCollectionViewCell.h"

@interface RDHomeTodayTableViewCell ()<UICollectionViewDelegate, UICollectionViewDataSource,UITextViewDelegate>

@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *collectionViewFlowLayout;
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UIView *noDataView;

@end

@implementation RDHomeTodayTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    [self setupUI];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setBloodSugarTodayArr:(NSMutableArray *)bloodSugarTodayArr{
    _bloodSugarTodayArr = bloodSugarTodayArr;
    
    if (bloodSugarTodayArr.count>0) {
        [self.noDataView setHidden:YES];
        [self.collectionView setHidden:NO];
    }else{
        [self.noDataView setHidden:NO];
        [self.collectionView setHidden:YES];
    }
    
    
    [self.collectionView reloadData];
}

- (void)setupUI{
    self.collectionViewFlowLayout.minimumLineSpacing = 5;
    self.collectionViewFlowLayout.minimumInteritemSpacing = 0;
    self.collectionViewFlowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.collectionViewFlowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.backgroundColor = [UIColor colorNamed:@"白色"];
    self.collectionView.showsVerticalScrollIndicator = NO;
    self.collectionView.showsHorizontalScrollIndicator = NO;
    
    [self.collectionView registerNib:[UINib nibWithNibName:@"RDHomeTodayCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"kRDHomeTodayCollectionViewCellID"];

}


- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {

    return CGSizeMake(SCREEN_WIDTH/4.0, 80);
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return self.bloodSugarTodayArr.count;
}

- ( UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    RDHomeTodayCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"kRDHomeTodayCollectionViewCellID" forIndexPath:indexPath];
    cell.model = self.bloodSugarTodayArr[indexPath.row];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
 
}


@end
